package com.neusoft.neuiotms.dcam.fixed.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcam.fixed.dto.InventoryDutyDTO;
import com.neusoft.neuiotms.dcam.fixed.service.InventoryResultTemporaryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "已选资产临时表接口")
@RestController
@RequestMapping("/api/w/fixed/inventory/results/temporary")
public class InventoryResultTemporaryController {

    @Autowired
    private InventoryResultTemporaryService inventoryResultTemporaryService;

    @ApiOperation("跟据任务id查询全部")
    @GetMapping
    public ResultListDTO<?> list(final Searchable searchable, final UserBean userBean) {
        final List<Map<String, Object>> list =
                this.inventoryResultTemporaryService.list(searchable.getLongValue("id"), userBean);
        return ResultListDTO.success(list);
    }

    @ApiOperation("跟据任务id查询全部")
    @PostMapping
    public ResultDTO<InventoryDutyDTO> create(@RequestBody final InventoryDutyDTO dto, final UserBean userBean) {
        final InventoryDutyDTO dutyDTO = this.inventoryResultTemporaryService.create(dto, userBean);
        return ResultDTO.success(dutyDTO);
    }

    @ApiOperation("根据dutyid清空临时表")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id, final UserBean userBean) {
        this.inventoryResultTemporaryService.delete(id, userBean);
        return ResultDTO.success();
    }
}
